package com.hckjsec.cloud.controller;

import java.io.File;
import java.math.BigDecimal;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;

import com.alibaba.fastjson.JSON;
import com.hckjsec.cloud.WebSocket.WebSocketServer;
import com.hckjsec.cloud.domain.*;
import com.hckjsec.cloud.domain.homeView.*;
import com.hckjsec.cloud.domain.videoView.*;
import com.hckjsec.cloud.domain.view.BasicView;
import com.hckjsec.cloud.domain.view.KvView;
import com.hckjsec.cloud.domain.view.QysView;
import com.hckjsec.cloud.domain.wechatDataView.CurrencyView;
import com.hckjsec.cloud.service.*;
import com.hckjsec.common.config.FileInfoTempView;
import com.hckjsec.common.config.FileInfoView;
import com.hckjsec.common.config.JeeThinkConfig;
import com.hckjsec.common.constant.Constants;
import com.hckjsec.common.core.domain.entity.SysDictData;
import com.hckjsec.common.core.redis.RedisCache;
import com.hckjsec.common.enums.SysFileTypeEnum;
import com.hckjsec.common.image.CenerateSignImage;
import com.hckjsec.common.init.YwInitData;
import com.hckjsec.common.qiyuesuo.QysUser;
import com.hckjsec.common.qiyuesuo.SendByCodeSetting;
import com.hckjsec.common.utils.*;
import com.hckjsec.common.utils.file.FileUploadUtils;
import com.hckjsec.system.service.ISysDictTypeService;
import com.qiyuesuo.sdk.v2.SdkClient;
import com.qiyuesuo.sdk.v2.bean.Contract;
import com.qiyuesuo.sdk.v2.bean.Stamper;
import com.qiyuesuo.sdk.v2.response.DocumentAddResult;
import com.qiyuesuo.sdk.v2.response.SdkResponse;
import org.apache.poi.ss.usermodel.DateUtil;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.hckjsec.common.annotation.Log;
import com.hckjsec.common.core.controller.BaseController;
import com.hckjsec.common.core.domain.AjaxResult;
import com.hckjsec.common.enums.BusinessType;
import com.hckjsec.common.utils.poi.ExcelUtil;
import com.hckjsec.common.core.page.TableDataInfo;

import static com.hckjsec.common.utils.ZipUtils.zipFiles;

/**
 * 申办信息Controller
 * 
 * @author cyt
 * @date 2021-08-23
 */
@RestController
@RequestMapping("/system/applicationApply")
public class AppletsBusinessController extends BaseController
{
    @Autowired
    private IAppletsBusinessService appletsBusinessService;

    @Autowired
    private IAppletsBusinessMatterService appletsBusinessMatterService;

    @Autowired
    private IAppletsBusinessMatterApplicantService appletsBusinessMatterApplicantService;

    @Autowired
    private IAppletsApplicantUserService appletsApplicantUserService;

    @Autowired
    private IAppletsBusinessMaterialService appletsBusinessMaterialService;

    @Autowired
    private IAppletsBusinessCostService appletsBusinessCostService;

    @Autowired
    private ISysDictTypeService dictTypeService;

    @Autowired
    private WxSendTplMessageService wxSendTplMessageService;

    @Autowired
    private YwInitData ywInitData;

    @Autowired
    private IAppletsBusinessVideoService appletsBusinessVideoService;

    @Autowired
    private IAppletsBusinessVideoUserService appletsBusinessVideoUserService;

    @Autowired
    private RedisCache redisCache;

    @Autowired
    private IAppletsBusinessVideoSignService appletsBusinessVideoSignService;

    @Autowired
    private IAppletsBusinessVideoSigncoorService appletsBusinessVideoSigncoorService;

    @Autowired
    private IAppletsBusinessTemplateLogService appletsBusinessTemplateLogService;
    /**
     * 查询申办信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:applicationApply:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppletsBusiness appletsBusiness)
    {
        startPage();
        if(!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
            appletsBusiness.setDeptId(SecurityUtils.getDeptId());
        }
        List<AppletsBusiness> list = appletsBusinessService.selectAppletsBusinessList(appletsBusiness);
        list.forEach(kv->{
            List<AppletsBusinessMatter> appletsBusinessMatter = appletsBusinessMatterService.selectAppletsBusinessMatterList(new AppletsBusinessMatter(kv.getId()));
            kv.setMatterCount(appletsBusinessMatter.size());
            List<String> videoXx = new ArrayList<>();
            AppletsBusinessVideo appletsBusinessVideo=new AppletsBusinessVideo();
            appletsBusinessVideo.setBusinessid(kv.getId());
            List<AppletsBusinessVideo> appletsBusinessVideoList=appletsBusinessVideoService.selectAppletsBusinessVideoList(appletsBusinessVideo);
            appletsBusinessVideoList.forEach(vv->{
                if (!"".equals(StringUtils.isHcNull(vv.getVideoUrl(),""))){
                    videoXx.add(vv.getVideoUrl());
                }
            });
            if (videoXx.size()>0){
                kv.setVideo(true);
            }else{
                kv.setVideo(false);
            }
        });
        return getDataTable(list);
    }

    /**
     * 导出申办信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:applicationApply:list')")
    @Log(title = "申办信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AppletsBusiness appletsBusiness)
    {
        List<AppletsBusiness> list = appletsBusinessService.selectAppletsBusinessList(appletsBusiness);
        ExcelUtil<AppletsBusiness> util = new ExcelUtil<AppletsBusiness>(AppletsBusiness.class);
        return util.exportExcel(list, "business");
    }

    /**
     * 删除案件信息
     */
    @Log(title = "删除案件", businessType = BusinessType.DELETE)
    @GetMapping("/deleteBusiness/{businessid}")
    public AjaxResult deleteBusiness(@PathVariable("businessid") String businessids)
    {
        if (StringUtils.isNull(businessids)){
            return AjaxResult.cloud_602("无案件!");
        }
        String[] businessidArr=businessids.split(",");
        if(SecurityUtils.isAdmin(SecurityUtils.getUserId())){
            for (int i = 0; i < businessidArr.length ; i++) {
                String businessid = businessidArr[i];
                AppletsBusiness oneBusiness = new AppletsBusiness();
                oneBusiness.setBusinessid(businessid);
                List<AppletsBusiness> appletsBusinessList = appletsBusinessService.selectAppletsBusinessList(oneBusiness);
                appletsBusinessList.forEach(kv->{
                    long id = kv.getId();
                    appletsBusinessService.deleteAppletsBusinessById(id);
                    //费用
                    AppletsBusinessCost  appletsBusinessCost = new AppletsBusinessCost();
                    appletsBusinessCost.setBusinessid(id);
                    List<AppletsBusinessCost> appletsBusinessCostList = appletsBusinessCostService.selectAppletsBusinessCostList(appletsBusinessCost);
                    appletsBusinessCostList.forEach(one->{
                        appletsBusinessCostService.deleteAppletsBusinessCostById(one.getId());
                    });
                    //材料
                    AppletsBusinessMaterial appletsBusinessMaterial = new AppletsBusinessMaterial();
                    appletsBusinessMaterial.setBusinessid(id);
                    List<AppletsBusinessMaterial> appletsBusinessMaterialList = appletsBusinessMaterialService.selectAppletsBusinessMaterialList(appletsBusinessMaterial);
                    appletsBusinessMaterialList.forEach(two->{
                        appletsBusinessMaterialService.deleteAppletsBusinessMaterialById(two.getId());
                    });
                    //事项
                    AppletsBusinessMatter appletsBusinessMatter = new AppletsBusinessMatter();
                    appletsBusinessMatter.setBusinessid(id);
                    List<AppletsBusinessMatter> appletsBusinessMatterList = appletsBusinessMatterService.selectAppletsBusinessMatterList(appletsBusinessMatter);
                    appletsBusinessMatterList.forEach(three->{
                        appletsBusinessMatterService.deleteAppletsBusinessMatterById(three.getId());
                    });
                    //事项当事人
                    AppletsBusinessMatterApplicant appletsBusinessMatterApplicant = new AppletsBusinessMatterApplicant();
                    appletsBusinessMatterApplicant.setBusinessid(id);
                    List<AppletsBusinessMatterApplicant> appletsBusinessMatterApplicantList = appletsBusinessMatterApplicantService.selectAppletsBusinessMatterApplicantList(appletsBusinessMatterApplicant);
                    appletsBusinessMatterApplicantList.forEach(four->{
                        appletsBusinessMatterApplicantService.deleteAppletsBusinessMatterApplicantById(four.getId());
                    });
                    //视频
                    AppletsBusinessVideo appletsBusinessVideo = new AppletsBusinessVideo();
                    appletsBusinessVideo.setBusinessid(id);
                    List<AppletsBusinessVideo> appletsBusinessVideoList = appletsBusinessVideoService.selectAppletsBusinessVideoList(appletsBusinessVideo);
                    appletsBusinessVideoList.forEach(five->{
                        appletsBusinessVideoService.deleteAppletsBusinessVideoById(five.getId());
                        AppletsBusinessVideoSign appletsBusinessVideoSign = new AppletsBusinessVideoSign();
                        appletsBusinessVideoSign.setVideoid(five.getId());
                        List<AppletsBusinessVideoSign> appletsBusinessVideoSignList = appletsBusinessVideoSignService.selectAppletsBusinessVideoSignList(appletsBusinessVideoSign);
                        appletsBusinessVideoSignList.forEach(six->{
                            appletsBusinessVideoSignService.deleteAppletsBusinessVideoSignById(six.getUuid());
                            appletsBusinessVideoSigncoorService.deleteAppletsBusinessVideoSigncoorByUuid(six.getUuid());
                        });

                        //视频人员
                        AppletsBusinessVideoUser appletsBusinessVideoUser = new AppletsBusinessVideoUser();
                        appletsBusinessVideoUser.setVideoid(five.getId());
                        List<AppletsBusinessVideoUser> appletsBusinessVideoUserList = appletsBusinessVideoUserService.selectAppletsBusinessVideoUserList(appletsBusinessVideoUser);
                        appletsBusinessVideoUserList.forEach(eight->{
                            appletsBusinessVideoUserService.deleteAppletsBusinessVideoUserById(eight.getId());
                        });
                    });

                });
                AppletsBusinessTemplateLog appletsBusinessTemplateLog = new AppletsBusinessTemplateLog();
                appletsBusinessTemplateLog.setBusinessid(businessid);
                List<AppletsBusinessTemplateLog> appletsBusinessTemplateLogList = appletsBusinessTemplateLogService.selectAppletsBusinessTemplateLogList(appletsBusinessTemplateLog);
                appletsBusinessTemplateLogList.forEach(nine->{
                    appletsBusinessTemplateLogService.deleteAppletsBusinessTemplateLogById(nine.getId());
                });
            }
            return AjaxResult.success();
        }
        return AjaxResult.error();
    }

    /**
     * 获取申办信息详细信息-审核信息
     */
    @PreAuthorize("@ss.hasPermi('system:applicationApply:audit')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        Map<String,String> zjlxryMap = new HashMap<String,String>();
        Map<String,String> zjlxdwMap = new HashMap<String,String>();
        Map<Long,String> sxMap = new HashMap<Long,String>();
        List<SysDictData> zjlxryList=dictTypeService.selectDictDataByType(ComUtil.CONFIG_PERSONNELTYPE);
        zjlxryList.forEach(clKv ->{
            zjlxryMap.put(clKv.getDictValue(),clKv.getDictLabel());
        });
        List<SysDictData> zjlxdwList=dictTypeService.selectDictDataByType(ComUtil.CONFIG_COMPANYTYPE);
        zjlxdwList.forEach(clKv ->{
            zjlxdwMap.put(clKv.getDictValue(),clKv.getDictLabel());
        });
        AppletsBusiness appletsBusiness=appletsBusinessService.selectAppletsBusinessById(id);
        PublicAppletsBusiness publicAppletsBusiness = new PublicAppletsBusiness();
        publicAppletsBusiness.setAppletsBusiness(appletsBusiness);
        List<AppletsBusinessMatter> appletsBusinessMatter = appletsBusinessMatterService.selectAppletsBusinessMatterList(new AppletsBusinessMatter(id));
        appletsBusinessMatter.forEach(kv->{
            sxMap.put(kv.getId(),kv.getMattername());
        });

        publicAppletsBusiness.setAppletsBusinessMatter(appletsBusinessMatter);
        List<AppletsBusinessMatterApplicant> selectAppletsBusinessMatterApplicantList=appletsBusinessMatterApplicantService.selectAppletsBusinessMatterApplicantList(new AppletsBusinessMatterApplicant(id));
        List<Long> applicantIdList=new ArrayList<>();
        selectAppletsBusinessMatterApplicantList.forEach(kv->{
            if(!applicantIdList.contains(kv.getApplicantid())){
                applicantIdList.add(kv.getApplicantid());
            }
        });
        Long[] ids=applicantIdList.toArray(new Long[applicantIdList.size()]);
        List<AppletsApplicantUser> appletsApplicantUser=appletsApplicantUserService.selectAppletsApplicantUserByIdList(ids);
        appletsApplicantUser.forEach(kv->{
               if ("1".equals(kv.getUsertype())){
                   kv.setCertificatestype(zjlxryMap.get(kv.getCertificatestype().trim()));
               }else{
                   kv.setCertificatestype(zjlxdwMap.get(kv.getCertificatestype().trim()));
               }
        });
        publicAppletsBusiness.setAppletsApplicantUser(appletsApplicantUser);
        List<AppletsBusinessMaterial> appletsBusinessMaterial=appletsBusinessMaterialService.selectAppletsBusinessMaterialList(new AppletsBusinessMaterial(id));
        publicAppletsBusiness.setAppletsBusinessMaterial(appletsBusinessMaterial);
        List<AppletsBusinessCost> appletsBusinessCost=appletsBusinessCostService.selectAppletsBusinessCostList(new AppletsBusinessCost(id));
        appletsBusinessCost.forEach(kv->{
            kv.setMattername(sxMap.get(kv.getMatterid()));
        });
        publicAppletsBusiness.setAppletsBusinessCost(appletsBusinessCost);
        return AjaxResult.success(publicAppletsBusiness);
    }

    /**
     * 获取申办信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:applicationApply:audit')")
    @GetMapping(value = "/details/{id}")
    public AjaxResult getDetails(@PathVariable("id") Long id)
    {
        Map<String,String> zjlxryMap = new HashMap<String,String>();
        Map<String,String> zjlxdwMap = new HashMap<String,String>();
        Map<Long,String> sxMap = new HashMap<Long,String>();
        List<SysDictData> zjlxryList=dictTypeService.selectDictDataByType(ComUtil.CONFIG_PERSONNELTYPE);
        zjlxryList.forEach(clKv ->{
            zjlxryMap.put(clKv.getDictValue(),clKv.getDictLabel());
        });
        List<SysDictData> zjlxdwList=dictTypeService.selectDictDataByType(ComUtil.CONFIG_COMPANYTYPE);
        zjlxdwList.forEach(clKv ->{
            zjlxdwMap.put(clKv.getDictValue(),clKv.getDictLabel());
        });
        AppletsBusiness appletsBusiness=appletsBusinessService.selectAppletsBusinessById(id);
        PublicAppletsBusiness publicAppletsBusiness = new PublicAppletsBusiness();
        publicAppletsBusiness.setAppletsBusiness(appletsBusiness);
        List<AppletsBusinessMatter> appletsBusinessMatter = appletsBusinessMatterService.selectAppletsBusinessMatterList(new AppletsBusinessMatter(id));
        appletsBusinessMatter.forEach(kv->{
            sxMap.put(kv.getId(),kv.getMattername());
        });

        publicAppletsBusiness.setAppletsBusinessMatter(appletsBusinessMatter);
        List<AppletsBusinessMatterApplicant> selectAppletsBusinessMatterApplicantList=appletsBusinessMatterApplicantService.selectAppletsBusinessMatterApplicantList(new AppletsBusinessMatterApplicant(id));
        List<Long> applicantIdList=new ArrayList<>();
        selectAppletsBusinessMatterApplicantList.forEach(kv->{
            if(!applicantIdList.contains(kv.getApplicantid())){
                applicantIdList.add(kv.getApplicantid());
            }
        });
        Long[] ids=applicantIdList.toArray(new Long[applicantIdList.size()]);
        List<AppletsApplicantUser> appletsApplicantUser=appletsApplicantUserService.selectAppletsApplicantUserByIdList(ids);
        appletsApplicantUser.forEach(kv->{
            if ("1".equals(kv.getUsertype())){
                kv.setCertificatestype(zjlxryMap.get(kv.getCertificatestype().trim()));
            }else{
                kv.setCertificatestype(zjlxdwMap.get(kv.getCertificatestype().trim()));
            }
        });
        publicAppletsBusiness.setAppletsApplicantUser(appletsApplicantUser);
        List<AppletsBusinessMaterial> appletsBusinessMaterial=appletsBusinessMaterialService.selectAppletsBusinessMaterialList(new AppletsBusinessMaterial(id));
        publicAppletsBusiness.setAppletsBusinessMaterial(appletsBusinessMaterial);
        List<AppletsBusinessCost> appletsBusinessCost=appletsBusinessCostService.selectAppletsBusinessCostList(new AppletsBusinessCost(id));
        appletsBusinessCost.forEach(kv->{
            kv.setMattername(sxMap.get(kv.getMatterid()));
        });
        publicAppletsBusiness.setAppletsBusinessCost(appletsBusinessCost);

        List<AppletsBusinessVideo> appletsBusinessVideos = new ArrayList<>();
        List<AppletsBusinessVideoSign> appletsBusinessVideoSigns = new ArrayList<>();
        AppletsBusinessVideo appletsBusinessVideo=new AppletsBusinessVideo();
        appletsBusinessVideo.setBusinessid(id);
        List<AppletsBusinessVideo> appletsBusinessVideoList=appletsBusinessVideoService.selectAppletsBusinessVideoList(appletsBusinessVideo);
        appletsBusinessVideoList.forEach(kv->{
            if (!"".equals(StringUtils.isHcNull(kv.getVideoUrl(),""))){
                appletsBusinessVideos.add(kv);
            }
            Long videoId=kv.getId();
            List<AppletsBusinessVideoSign>   appletsBusinessVideoSignList = appletsBusinessVideoSignService.selectAppletsBusinessVideoSignList(new AppletsBusinessVideoSign(videoId));
            appletsBusinessVideoSignList.forEach(sign->{
                if (!"-1".equals(StringUtils.isHcNull(sign.getContractid(),""))){
                    appletsBusinessVideoSigns.add(sign);
                }
            });
        });
        publicAppletsBusiness.setAppletsBusinessVideos(appletsBusinessVideos);
        publicAppletsBusiness.setAppletsBusinessVideoSigns(appletsBusinessVideoSigns);
        return AjaxResult.success(publicAppletsBusiness);
    }
    /**
     * 获取修改费用信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:applicationApply:audit')")
    @GetMapping(value = "/getCost")
    public AjaxResult getInfoCost(AppletsBusinessCost appletsBusinessCost)
    {
        List<AppletsBusinessCost> appletsBusinessCostList=appletsBusinessCostService.selectAppletsBusinessCostList(new AppletsBusinessCost(appletsBusinessCost.getBusinessid(),appletsBusinessCost.getMatterid()));
        return AjaxResult.success(appletsBusinessCostList);
    }
    /**
     * 保存费用信息
     */
    @PreAuthorize("@ss.hasPermi('system:applicationApply:audit')")
    @PostMapping(value = "/saveCost")
    public AjaxResult saveCost(@RequestBody SaveBusinessCost saveBusinessCost)
    {
        //1.获取案件对象
        //1.1遍历组装材料
        Map<String,String> fyMap = new HashMap<String,String>();
        List<SysDictData> selectDictDataByType=dictTypeService.selectDictDataByType(ComUtil.CONFIG_CHARGE);
        selectDictDataByType.forEach(clKv ->{
            fyMap.put(clKv.getDictValue(),clKv.getDictLabel());
        });
        AppletsBusiness appletsBusiness=appletsBusinessService.selectAppletsBusinessById(saveBusinessCost.getBusinessid());
        List<AppletsBusinessCost> appletsBusinessCostList=saveBusinessCost.getAppletsBusinessCostList();
        if (!StringUtils.isEmpty(appletsBusinessCostList)) {
            appletsBusinessCostService.deleteAppletsBusinessCostByMattid(new AppletsBusinessCost(saveBusinessCost.getBusinessid(),saveBusinessCost.getMatterid()));
            appletsBusinessCostList.forEach(kv->{
                AppletsBusinessCost appletsBusinessCost = new AppletsBusinessCost();
                appletsBusinessCost.setConfigId(appletsBusiness.getConfigId());
                appletsBusinessCost.setDeptId(appletsBusiness.getDeptId());
                appletsBusinessCost.setBusinessid(saveBusinessCost.getBusinessid());
                appletsBusinessCost.setMatterid(saveBusinessCost.getMatterid());
                appletsBusinessCost.setCost(kv.getCost());
                appletsBusinessCost.setCostname(fyMap.get(kv.getCost()));
                appletsBusinessCost.setTotalmoney(kv.getTotalmoney());
                appletsBusinessCost.setPaidmoney(new BigDecimal("0"));
                appletsBusinessCostService.insertAppletsBusinessCost(appletsBusinessCost);
            });
        }
        appletsBusinessService.updateCostAndMatter(saveBusinessCost.getBusinessid());
        return AjaxResult.success();
    }

    /**
     * 修改申办信息-审核
     */
    @PreAuthorize("@ss.hasPermi('system:applicationApply:audit')")
    @Log(title = "申办信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppletsBusiness appletsBusiness)
    {
        AppletsBusiness newAppletsBusiness=appletsBusinessService.selectAppletsBusinessById(appletsBusiness.getId());
        newAppletsBusiness.setState(appletsBusiness.getState());
        newAppletsBusiness.setRemarks(appletsBusiness.getRemarks());
        newAppletsBusiness.setAuditor(SecurityUtils.getUserId());
        newAppletsBusiness.setAuditortime(DateUtils.parseDate(DateUtils.getTime()));
        int rows=appletsBusinessService.updateAppletsBusiness(newAppletsBusiness);
        if (rows > 0){//发送消息
                if("2".equals(newAppletsBusiness.getState()) || "98".equals(newAppletsBusiness.getState())){//审核同意或不同意
                    wxSendTplMessageService.sendMessageSetMaterial("bid",newAppletsBusiness.getConfigId(),newAppletsBusiness,"");
                }else if("0".equals(newAppletsBusiness.getState())){//补材料
                    wxSendTplMessageService.sendMessageSetMaterial("materials",newAppletsBusiness.getConfigId(),newAppletsBusiness,"");
                }
        }
        return toAjax(rows);
    }

    /**
     * 材料下载
     */
    @PreAuthorize("@ss.hasPermi('system:applicationApply:audit')")
    @GetMapping(value = "/downloadMaterial/{id}")
    public AjaxResult downloadMaterial(@PathVariable("id") Long id)
    {
        AppletsBusiness appletsBusiness =appletsBusinessService.selectAppletsBusinessById(id);
        List<AppletsBusinessMaterial> appletsBusinessMaterial=appletsBusinessMaterialService.selectAppletsBusinessMaterialList(new AppletsBusinessMaterial(id));
        if (StringUtils.isEmpty(appletsBusinessMaterial) ){
            return AjaxResult.cloud_602("没有待下载的材料!");
        }
        List<File> srcList = new ArrayList<File>();
        String fileName=appletsBusiness.getBusinessid()+"-"+ComUtil.getRandom(2)+".zip";
        String zipPath=JeeThinkConfig.getDownloadPath()+fileName;
        appletsBusinessMaterial.forEach(kv->{
            String htPath= JeeThinkConfig.getProfile()+kv.getMaterialpath();
            srcList.add(new File(htPath));
        });
        File[] srcFiles = srcList.stream().toArray(File[]::new);
        boolean flag = zipFiles(srcFiles, new File(zipPath));
        if (!flag){
            return AjaxResult.cloud_602("打包失败!");
        }
        return AjaxResult.success("操作成功",fileName);
    }

    /**
     * 开视频
     */
    @PreAuthorize("@ss.hasPermi('system:applicationApply:video')")
    @GetMapping(value = "/openVideo/{id}")
    public AjaxResult openVideo(@PathVariable("id") Long id)
    {
        AppletsBusiness appletsBusiness=appletsBusinessService.selectAppletsBusinessById(id);
        Long configId=appletsBusiness.getConfigId();
        BasicView basicView= JSON.parseObject(JSON.toJSONString(ywInitData.getIdByBasicViewMap().get(configId)),BasicView.class);
        AppletsConfig appletsConfig=JSON.parseObject(JSON.toJSONString(ywInitData.getIdByConfigViewMap().get(configId)),AppletsConfig.class);
        WxVideoCallView wxVideoCallView=new WxVideoCallView(basicView.getRemotevideo().getAppid(),basicView.getRemotevideo().getKey(),String.valueOf(SecurityUtils.getUserId()),SecurityUtils.getNickName());
        wxVideoCallView.setBusinessId(id);
        AppletsBusinessVideo appletsBusinessVideo = new AppletsBusinessVideo(wxVideoCallView.getRoomId(),wxVideoCallView.getCustomroomid());
        appletsBusinessVideo.setConfigId(appletsBusiness.getConfigId());
        appletsBusinessVideo.setDeptId(appletsBusiness.getDeptId());
        appletsBusinessVideo.setBusinessid(id);
        appletsBusinessVideo.setUserid(SecurityUtils.getUserId());
        appletsBusinessVideo.setUsername(SecurityUtils.getNickName());
        appletsBusinessVideo.setState("0");
        int rows=appletsBusinessVideoService.insertAppletsBusinessVideo(appletsBusinessVideo);
        wxVideoCallView.setVideoId(appletsBusinessVideo.getId());
        AppletsBusinessVideoUser appletsBusinessVideoUserWeb = new AppletsBusinessVideoUser();
        appletsBusinessVideoUserWeb.setConfigId(appletsBusiness.getConfigId());
        appletsBusinessVideoUserWeb.setDeptId(appletsBusiness.getDeptId());
        appletsBusinessVideoUserWeb.setVideoid(appletsBusinessVideo.getId());
        appletsBusinessVideoUserWeb.setOpenid("-1");
        appletsBusinessVideoUserWeb.setSigntype("web");
        appletsBusinessVideoUserWeb.setIsliving("-1");
        appletsBusinessVideoUserWeb.setSignuserid(SecurityUtils.getUserId());
        appletsBusinessVideoUserWeb.setSignusername(SecurityUtils.getNickName());
        int userrow=appletsBusinessVideoUserService.insertAppletsBusinessVideoUser(appletsBusinessVideoUserWeb);
        if (userrow > 0){
            wxVideoCallView.setSid(appletsBusinessVideoUserWeb.getId());
            WebSocketUser webSocketUser = new WebSocketUser(appletsBusinessVideoUserWeb.getId().toString(),"web",wxVideoCallView.getRoomId(),appletsBusinessVideoUserWeb.getId().toString(),SecurityUtils.getNickName());
            redisCache.setCacheObject(ComUtil.getWechatVideoRoomCacheKey(appletsBusinessVideoUserWeb.getId().toString()),webSocketUser, 4, TimeUnit.HOURS);//缓存用户和房间号
        }
        if (rows > 0){
            wxSendTplMessageService.sendMessageSetMaterial("video",configId,appletsBusiness,appletsBusinessVideo.getCustomroomid());
        }

        return AjaxResult.success(wxVideoCallView);
    }

    /**
     * 获取签字照片列表
     */
    @PreAuthorize("@ss.hasPermi('system:applicationApply:video')")
    @GetMapping(value = "/getOpenVideoUser/{id}")
    public AjaxResult getOpenVideoUser(@PathVariable("id") Long id)
    {
        List<AppletsBusinessVideoUser> signImageList = appletsBusinessVideoUserService.selectAppletsBusinessVideoUserList(new AppletsBusinessVideoUser(id,"applets"));
        return AjaxResult.success(signImageList);
    }



    /**
     * 获取签字回显信息
     */
    @PreAuthorize("@ss.hasPermi('system:applicationApply:video')")
    @GetMapping(value = "/getSignStr/{uuid}")
    public AjaxResult getSignStr(@PathVariable("uuid") String uuid)
    {
        String key= Constants.SYS_BUSINESSID_TEMP + uuid;
        FileInfoTempView fileInfoTempView1 =redisCache.getCacheObject(key);
        if (StringUtils.isNull(fileInfoTempView1)){
            return AjaxResult.success(null);
        }
        return AjaxResult.success(fileInfoTempView1.getSigstr());
    }

    /**
     * 存储回显信息
     */
    @PreAuthorize("@ss.hasPermi('system:applicationApply:video')")
    @PostMapping(value = "/setSignStr")
    public AjaxResult setSignStr(@RequestBody FileInfoTempView fileInfoTempView)
    {
        String key= Constants.SYS_BUSINESSID_TEMP + fileInfoTempView.getUuid();
        FileInfoTempView fileInfoTempView1 =redisCache.getCacheObject(key);
        fileInfoTempView1.setSigstr(fileInfoTempView.getSigstr());
        redisCache.deleteObject(key);
        redisCache.setCacheObject(key,fileInfoTempView1, 4, TimeUnit.HOURS);
        return AjaxResult.success();
    }


    /**
     * 保存签字
     */
    @PreAuthorize("@ss.hasPermi('system:applicationApply:video')")
    @PostMapping(value = "/saveSign")
    public AjaxResult saveSign(@RequestBody VideoSignView videoSignView)
    {
        AppletsBusinessVideo appletsBusinessVideo=appletsBusinessVideoService.selectAppletsBusinessVideoById(videoSignView.getVideoId());
        AppletsBusinessVideoSign appletsBusinessVideoSign=appletsBusinessVideoSignService.selectAppletsBusinessVideoSignById(videoSignView.getUuid());
        if (StringUtils.isNull(appletsBusinessVideoSign)){//新增
            AppletsBusinessVideoSign newAppletsBusinessVideoSign= new AppletsBusinessVideoSign();
            newAppletsBusinessVideoSign.setUuid(videoSignView.getUuid());
            newAppletsBusinessVideoSign.setConfigId(appletsBusinessVideo.getConfigId());
            newAppletsBusinessVideoSign.setDeptId(appletsBusinessVideo.getDeptId());
            newAppletsBusinessVideoSign.setVideoid(videoSignView.getVideoId());
            newAppletsBusinessVideoSign.setPdfwidth(videoSignView.getPdfWidth());
            newAppletsBusinessVideoSign.setPdfheight(videoSignView.getPdfHeight());
            String key= Constants.SYS_BUSINESSID_TEMP + videoSignView.getUuid();
            FileInfoTempView fileInfoTempView1 =redisCache.getCacheObject(key);
            newAppletsBusinessVideoSign.setFilename(fileInfoTempView1.getFileName());
            newAppletsBusinessVideoSign.setFilepath(fileInfoTempView1.getFilePath());
            newAppletsBusinessVideoSign.setSigstr(fileInfoTempView1.getSigstr());
            newAppletsBusinessVideoSign.setState("0");
            newAppletsBusinessVideoSign.setContractid("-1");
            newAppletsBusinessVideoSign.setDocid("-1");
            appletsBusinessVideoSignService.insertAppletsBusinessVideoSign(newAppletsBusinessVideoSign);
        }
        appletsBusinessVideoSigncoorService.deleteAppletsBusinessVideoSigncoorByUuid(videoSignView.getUuid());
        List<VideoSignCoorView> signsList=videoSignView.getSigns();
        signsList.forEach(kv->{
            AppletsBusinessVideoUser appletsBusinessVideoUser=appletsBusinessVideoUserService.selectAppletsBusinessVideoUserById(kv.getName());
            AppletsBusinessVideoSigncoor appletsBusinessVideoSigncoor = new AppletsBusinessVideoSigncoor();
            appletsBusinessVideoSigncoor.setConfigId(appletsBusinessVideo.getConfigId());
            appletsBusinessVideoSigncoor.setDeptId(appletsBusinessVideo.getDeptId());
            appletsBusinessVideoSigncoor.setUuid(videoSignView.getUuid());
            appletsBusinessVideoSigncoor.setUserid(kv.getName());
            appletsBusinessVideoSigncoor.setSignuserid(appletsBusinessVideoUser.getSignuserid());
            appletsBusinessVideoSigncoor.setSignusername(appletsBusinessVideoUser.getSignusername().trim());
            appletsBusinessVideoSigncoor.setState("0");
            appletsBusinessVideoSigncoor.setDocwidth(kv.getWidth());
            appletsBusinessVideoSigncoor.setDocheight(kv.getHeight());
            appletsBusinessVideoSigncoor.setDoctop(kv.getTop());
            appletsBusinessVideoSigncoor.setDocleft(kv.getLeft());
            appletsBusinessVideoSigncoor.setDocangle(kv.getAngle());
            appletsBusinessVideoSigncoor.setDocscalex(kv.getScaleX());
            appletsBusinessVideoSigncoor.setDocscaley(kv.getScaleY());
            appletsBusinessVideoSigncoor.setDocpagenum(kv.getPageNum());
            appletsBusinessVideoSigncoorService.insertAppletsBusinessVideoSigncoor(appletsBusinessVideoSigncoor);
        });
        return AjaxResult.success();
    }


    /**
     * 删除申办信息视频文书
     */
    @PreAuthorize("@ss.hasPermi('system:applicationApply:video')")
    @DeleteMapping(value = "/deleteSign/{uuid}")
    public AjaxResult edit(@PathVariable("uuid") String uuid)
    {
        appletsBusinessVideoSignService.deleteAppletsBusinessVideoSignById(uuid);
        appletsBusinessVideoSigncoorService.deleteAppletsBusinessVideoSigncoorByUuid(uuid);
        return AjaxResult.success();
    }


    /**
     * 发送签字
     */
    @PreAuthorize("@ss.hasPermi('system:applicationApply:video')")
    @PostMapping(value = "/sendSign")
    public AjaxResult sendSign(@RequestBody VideoSignView videoSignView)
    {
        Long videoid=videoSignView.getVideoId();
        try {
            //1.先验证签署文书
            List<AppletsBusinessVideoSign>   appletsBusinessVideoSignList = appletsBusinessVideoSignService.selectAppletsBusinessVideoSignList(new AppletsBusinessVideoSign(videoid,"-1"));
            if (StringUtils.isEmpty(appletsBusinessVideoSignList) ){
                return AjaxResult.cloud_602("没有待发送的文书!");
            }
            Map<String,List<AppletsBusinessVideoSigncoor>> signcoorHt = new HashMap<>();//坐标信息map
            List<Long> signUserIdList=new ArrayList<>();//签字文书
            AtomicBoolean isCoor= new AtomicBoolean(true);
            appletsBusinessVideoSignList.forEach(kv->{
                List<AppletsBusinessVideoSigncoor>  appletsBusinessVideoSigncoorList= appletsBusinessVideoSigncoorService.selectAppletsBusinessVideoSigncoorList(new AppletsBusinessVideoSigncoor(kv.getUuid()));
                if (StringUtils.isEmpty(appletsBusinessVideoSigncoorList)){
                    isCoor.set(false);
                    return ;
                }
                signcoorHt.put(kv.getUuid(),appletsBusinessVideoSigncoorList);
                appletsBusinessVideoSigncoorList.forEach(sign->{
                    if(!signUserIdList.contains(sign.getSignuserid())){
                        signUserIdList.add(sign.getSignuserid());
                    }
                });
            });
            if(!isCoor.get()){
                return AjaxResult.cloud_602("存在文书未添加签字!");
            }
            Long[] ids=signUserIdList.toArray(new Long[signUserIdList.size()]);
            List<AppletsApplicantUser> appletsApplicantUserList=appletsApplicantUserService.selectAppletsApplicantUserByIdList(ids);
            List<QysUser> qysUserList = new ArrayList<>();
            appletsApplicantUserList.forEach(kv->{
                QysUser qysUser= new QysUser();
                qysUser.setName(kv.getName());
                qysUser.setCertificatesnumber(kv.getCertificatesnumber());
                if (!"".equals(StringUtils.isHcNull(kv.getPhone(),""))){
                    qysUser.setType("1");
                }else{
                    qysUser.setType("2");
                }
                qysUser.setPhone(kv.getPhone());
                qysUser.setMailbox(kv.getMailbox());
                qysUserList.add(qysUser);
            });
            //2.以下为发送契约锁签字
            AppletsBusinessVideo appletsBusinessVideo=appletsBusinessVideoService.selectAppletsBusinessVideoById(videoid);
            BasicView basicView= JSON.parseObject(JSON.toJSONString(ywInitData.getIdByBasicViewMap().get(appletsBusinessVideo.getConfigId())),BasicView.class);
            QysView qysView=basicView.getQys();
            if (StringUtils.isNull(qysView)){
                return AjaxResult.cloud_602("契约锁未配置!");
            }
            SdkClient client = new SdkClient(qysView.getUrl(), qysView.getAccesskey(), qysView.getAccessSecret());
            SdkResponse<Contract> draft = SendByCodeSetting.draftHks(client,qysUserList);
            List<Stamper> Stamperlist =  new ArrayList<Stamper>();
            Long contractId = draft.getResult().getId();//合同id
            appletsBusinessVideoSignList.forEach(kv->{
                    String name=kv.getFilename();
                    String htPath= JeeThinkConfig.getProfile()+kv.getFilepath();
                    SdkResponse<DocumentAddResult> fileAddResult = null;
                    try {
                        fileAddResult = SendByCodeSetting.addDocumentByFileHks(client, contractId, htPath, kv.getFilename());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    Long documentId1 = fileAddResult.getResult().getDocumentId();
                    List<AppletsBusinessVideoSigncoor> appletsBusinessVideoSigncoorList=signcoorHt.get(kv.getUuid());
                    appletsBusinessVideoSigncoorList.forEach(addSign->{
                             Stamper personalStamper = SendByCodeSetting.sendStamper1Hks(client, draft.getResult(), documentId1,addSign.getSignusername(),addSign.getDocpagenum(),addSign.getDoctop(),addSign.getDocleft(),kv.getPdfwidth(),kv.getPdfheight());
                             Stamperlist.add(personalStamper);
                    });
                    AppletsBusinessVideoSign  modAppletsBusinessVideoSign= appletsBusinessVideoSignService.selectAppletsBusinessVideoSignById(kv.getUuid());
                    modAppletsBusinessVideoSign.setContractid(String.valueOf(contractId));
                    modAppletsBusinessVideoSign.setDocid(String.valueOf(documentId1));
                    appletsBusinessVideoSignService.updateAppletsBusinessVideoSign(modAppletsBusinessVideoSign);
            });
            SendByCodeSetting.sendHks(client, draft.getResult(), Stamperlist);
            //通知websocket用户
            WebSocketServer.sendSign(appletsBusinessVideo.getRoomid());
        }catch (Exception e){
            e.printStackTrace();
            return AjaxResult.cloud_602("未知错误!");
        }
        return AjaxResult.success();
    }

    /**
     * 补签
     */
    @PreAuthorize("@ss.hasPermi('system:applicationApply:video')")
    @GetMapping(value = "/senSignature/{roomid}")
    public AjaxResult senSignature(@PathVariable("roomid") String roomid)
    {
        //通知websocket用户
        WebSocketServer.sendSign(roomid.trim());
        return AjaxResult.success();
    }

    /**
     * 获取未发送文书列表
     */
    @PreAuthorize("@ss.hasPermi('system:applicationApply:video')")
    @GetMapping(value = "/getVideoDocList/{videoid}")
    public AjaxResult getVideoDocList(@PathVariable("videoid") Long videoid)
    {
        List<GetVideoDoc> getVideoDocList= new ArrayList<>();
        List<AppletsBusinessVideoSign>   appletsBusinessVideoSignList = appletsBusinessVideoSignService.selectAppletsBusinessVideoSignList(new AppletsBusinessVideoSign(videoid));
        return AjaxResult.success(appletsBusinessVideoSignList);
    }

    /**
     * 发送短信列表
     */
    @PreAuthorize("@ss.hasPermi('system:applicationApply:video')")
    @PostMapping(value = "/sendSms")
    public AjaxResult sendSms(@RequestBody VideoSms videoSms)
    {
        AppletsBusinessVideo appletsBusinessVideo=appletsBusinessVideoService.selectAppletsBusinessVideoById(videoSms.getVideoId());
        List<String> phonelist = new ArrayList<String>();
        List<CurrencyView> phoneList=videoSms.getPhoneList();
        if (StringUtils.isEmpty(phoneList) ){
            return AjaxResult.cloud_602("没有待发送的手机号码!");
        }
        phoneList.forEach(kv->{
            phonelist.add("+86"+kv.getValue());
        });
        wxSendTplMessageService.sendAddOrder(phonelist, appletsBusinessVideo.getConfigId(), "8",appletsBusinessVideo.getCustomroomid(),"","");
        return AjaxResult.success();
    }

    /**
     * 获取契约锁文书详情列表
     */
    @PreAuthorize("@ss.hasPermi('system:applicationApply:video')")
    @GetMapping(value = "/getQysDocUrl/{uuid}")
    public AjaxResult getVideoDocList(@PathVariable("uuid") String uuid) throws  Exception
    {
        String url="";
        AppletsBusinessVideoSign appletsBusinessVideoSign=appletsBusinessVideoSignService.selectAppletsBusinessVideoSignById(uuid);
        List<AppletsBusinessVideoSigncoor>  appletsBusinessVideoSigncoorList= appletsBusinessVideoSigncoorService.selectAppletsBusinessVideoSigncoorList(new AppletsBusinessVideoSigncoor(uuid));
        Long signUserId=appletsBusinessVideoSigncoorList.get(0).getSignuserid();
        AppletsApplicantUser appletsApplicantUser=appletsApplicantUserService.selectAppletsApplicantUserById(signUserId);
        BasicView basicView= JSON.parseObject(JSON.toJSONString(ywInitData.getIdByBasicViewMap().get(appletsBusinessVideoSign.getConfigId())),BasicView.class);
        QysView qysView=basicView.getQys();
        if (StringUtils.isNull(qysView)){
            return AjaxResult.cloud_602("契约锁未配置!");
        }
        SdkClient client = new SdkClient(qysView.getUrl(), qysView.getAccesskey(), qysView.getAccessSecret());
        QysUser qysUser= new QysUser();
        qysUser.setName(appletsApplicantUser.getName());
        qysUser.setCertificatesnumber(appletsApplicantUser.getCertificatesnumber());
        if (!"".equals(StringUtils.isHcNull(appletsApplicantUser.getPhone(),""))){
            qysUser.setType("1");
        }else{
            qysUser.setType("2");
        }
        qysUser.setPhone(appletsApplicantUser.getPhone());
        qysUser.setMailbox(appletsApplicantUser.getMailbox());
        url=SendByCodeSetting.gerenateSignUrl(client,Long.valueOf(appletsBusinessVideoSign.getContractid()),qysUser);
        return AjaxResult.success("操作成功",url);
    }

    /**
     * 关闭视频
     */
    @PreAuthorize("@ss.hasPermi('system:applicationApply:video')")
    @PostMapping(value = "/closeVideo")
    public AjaxResult closeVideo(@RequestBody VideoSignView videoSignView)
    {
        Long videoid=videoSignView.getVideoId();
        //1.关闭视频录制
        AppletsBusinessVideo appletsBusinessVideo=appletsBusinessVideoService.selectAppletsBusinessVideoById(videoSignView.getVideoId());
        BasicView basicView= JSON.parseObject(JSON.toJSONString(ywInitData.getIdByBasicViewMap().get(appletsBusinessVideo.getConfigId())),BasicView.class);
        String  requestid=StringUtils.isHcNull(appletsBusinessVideo.getRequestid(),"");
        if (!"".equals(requestid)) {//关闭
            WxTencentCloudUtil.closehd(basicView.getRemotevideo().getSecretId(), basicView.getRemotevideo().getSecretKey(), basicView.getRemotevideo().getAppid(), appletsBusinessVideo.getRoomid());
        }
        appletsBusinessVideo.setState("1");
        appletsBusinessVideoService.updateAppletsBusinessVideo(appletsBusinessVideo);
        //2.通知手机端关闭
        WebSocketServer.closeRoom(appletsBusinessVideo.getRoomid());
        return AjaxResult.success();
    }

    /**
     * 根据id获取姓名
     */
    @PreAuthorize("@ss.hasPermi('system:applicationApply:video')")
    @GetMapping(value = "/getUserName/{id}")
    public AjaxResult getUserName(@PathVariable("id") Long id)
    {
        String  username="";
        AppletsApplicantUser appletsApplicantUser=appletsApplicantUserService.selectAppletsApplicantUserById(id);
        if (StringUtils.isNull(appletsApplicantUser)){
            username="屏幕分享";
        }else{
            username=appletsApplicantUser.getName();
        }
        return AjaxResult.success("操作成功",username);
    }

    /**
     * 首页数据
     */
    @GetMapping(value = "/getAppletsHome")
    public AjaxResult getAppletsHome()
    {
        Long dept = SecurityUtils.getDeptId();
        AppletsBusiness appletsBusiness = new AppletsBusiness();
        appletsBusiness.setDeptId(dept);
        AppletsHome appletsHome = new AppletsHome();
        List<AppletsBusiness> list = appletsBusinessService.selectAppletsBusinessList(appletsBusiness);
        Integer total = list.size();
        appletsHome.setTotal(total);
        List<Map<String,Integer>> stateMap= appletsBusinessService.findStateByNumMap(dept);
        Map<String,String> stateHt = ComUtil.mapListByBigIntegerMap(stateMap,"state");
        Integer agreeTotal = 0;
        if (stateHt.containsKey("2")){
            agreeTotal=StringUtils.StringToInt(stateHt.get("2"));
        }
        appletsHome.setAgreeTotal(agreeTotal);
        Integer revokeTotal = 0;
        if (stateHt.containsKey("98")){
            revokeTotal=StringUtils.StringToInt(stateHt.get("98"));
        }
        appletsHome.setRevokeTotal(revokeTotal);
        Integer toBereviewedTotal = 0;
        if (stateHt.containsKey("1")){
            toBereviewedTotal=StringUtils.StringToInt(stateHt.get("1"));
        }
        Integer materialTotal = 0;
        if (stateHt.containsKey("0")){
            materialTotal=StringUtils.StringToInt(stateHt.get("0"));
        }
        appletsHome.setToBereviewedProportion(ComUtil.percentInstance(toBereviewedTotal,total));
        appletsHome.setReviewedProportion(ComUtil.percentInstance(agreeTotal,total));
        appletsHome.setMaterialProportion(ComUtil.percentInstance(materialTotal,total));
        appletsHome.setRefuseProportion(ComUtil.percentInstance(revokeTotal,total));
        appletsBusiness.setState("1");
        List<AppletsBusiness> list3 = appletsBusinessService.selectAppletsBusinessList(appletsBusiness);
        appletsHome.setBidList(list3);
        /************以下代码为垃圾代码，有时间再改*****************/
        LinkedHashMap<String, Integer> CategoryHashMap = new LinkedHashMap<String, Integer>();
        Map<String,String> CategoryNameMap = new HashMap<>();
        List<SysDictData> selectDictDataByType=dictTypeService.selectDictDataByType(ComUtil.CONFIG_CATEGORY);
        selectDictDataByType.forEach(category->{
            CategoryHashMap.put(category.getDictValue(),0);
            CategoryNameMap.put(category.getDictValue(),category.getDictLabel());
        });
        list.forEach(kv->{
            int value=0;
            String category = kv.getCategory();
            if (CategoryHashMap.containsKey(category)){
                value=CategoryHashMap.get(category);
            }
            value++;
            CategoryHashMap.put(category,value);
        });
        CategoryHomeView categoryHomeView = new CategoryHomeView();
        List<AppletsCategoryView> appletsCategoryViewList = new ArrayList<>();
        CategoryHashMap.forEach((k,v)->{
            AppletsCategoryView appletsCategoryView = new AppletsCategoryView();
            appletsCategoryView.setValue(v);
            appletsCategoryView.setName(CategoryNameMap.get(k));
            appletsCategoryViewList.add(appletsCategoryView);
        });
        categoryHomeView.setData(appletsCategoryViewList);
        categoryHomeView.setAnimationDuration(total);
        appletsHome.setCategory(categoryHomeView);
        //事项列表
        LinkedHashMap<String, Integer> dateHashMap = new LinkedHashMap<String, Integer>();
        LinkedHashMap<String, Integer> dateUserHashMap = new LinkedHashMap<String, Integer>();
        MatterHomeView matterHomeView = new MatterHomeView();
        ArrayList<String> rqList= DateUtils.getPastList(15);
        List<Integer> bussinessList= new ArrayList<>();
        List<Integer> dateUserList= new ArrayList<>();
        List<String> rqSubList= new ArrayList<>();
        for (String rq : rqList){
            String rqSub=rq.substring(5);
            rqSubList.add(rqSub);
            dateHashMap.put(rq,0);
            dateUserHashMap.put(rq,0);
        }
        String[] ss = rqSubList.stream().toArray(String[]::new);
        matterHomeView.setData(ss);
        list.forEach(kv->{
            int value=0;
            String operatortime = DateUtils.dateTime(kv.getOperatortime());
            if (dateHashMap.containsKey(operatortime)){
                value=dateHashMap.get(operatortime);
            }
            value++;
            dateHashMap.put(operatortime,value);
        });
        for (String rq : rqList){
            bussinessList.add(dateHashMap.get(rq));
        }
        List<AppletsMatterView> seriesList = new ArrayList<>();
        AppletsMatterView appletsMatterView = new AppletsMatterView();
        appletsMatterView.setName("新增订单");
        appletsMatterView.setData(bussinessList.stream().toArray(Integer[]::new));
        seriesList.add(appletsMatterView);

        //新增用户数据
        AppletsApplicantUser appletsApplicantUser = new AppletsApplicantUser();
        appletsApplicantUser.setDeptId(dept);
        appletsApplicantUser.setIsself("TRUE");
        List<AppletsApplicantUser> appletsApplicantUserList = appletsApplicantUserService.selectAppletsApplicantUserList(appletsApplicantUser);
        appletsApplicantUserList.forEach(kv->{
            int value=0;
            String operatortime = DateUtils.dateTime(kv.getOperatortime());
            if (dateUserHashMap.containsKey(operatortime)){
                value=dateUserHashMap.get(operatortime);
            }
            value++;
            dateUserHashMap.put(operatortime,value);
        });
        for (String rq : rqList){
            dateUserList.add(dateUserHashMap.get(rq));
        }
        AppletsMatterView appletsUserView = new AppletsMatterView();
        appletsUserView.setName("新增用户");
        appletsUserView.setData(dateUserList.stream().toArray(Integer[]::new));
        seriesList.add(appletsUserView);
        matterHomeView.setSeries(seriesList);
        appletsHome.setDateReport(matterHomeView);
        return AjaxResult.success(appletsHome);
    }










    /**
     * 查询开视频的案件
     */
    @GetMapping("/getVideoList")
    public AjaxResult getVideoList(AppletsBusiness appletsBusiness)
    {
        if(!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
            appletsBusiness.setDeptId(SecurityUtils.getDeptId());
        }
        List<AppletsBusiness> list = appletsBusinessService.selectAppletsBusinessVideoList(appletsBusiness);
        Map<Long,Long> collect = list.stream().collect(Collectors.groupingBy(AppletsBusiness::getDeptId,Collectors.counting()));
        List<AppletsBusiness> findList = new ArrayList<>();
        collect.forEach((k,v)->{
            AppletsBusiness business = new  AppletsBusiness();
            business.setDeptId(k);
            business.setDeptName(ywInitData.getDeptMap().get(k));
            business.setCount(v.intValue());
            findList.add(business);
        });
        return AjaxResult.success(findList);
    }


    /**
     * 查询开视频的案件
     */
    @GetMapping("/getVideoDataList")
    public AjaxResult getVideoDataList(AppletsBusiness appletsBusiness)
    {
        if(!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
            appletsBusiness.setDeptId(SecurityUtils.getDeptId());
        }
        List<AppletsBusiness> list = appletsBusinessService.selectAppletsBusinessVideoList(appletsBusiness);
        list.forEach(kv->{
            kv.setDeptName(ywInitData.getDeptMap().get(kv.getDeptId()));
        });
        return AjaxResult.success(list);
    }

    /**
     * 导出开视频的案件列表
     */
    @Log(title = "导出开视频的案件列表", businessType = BusinessType.EXPORT)
    @GetMapping("/videoExport")
    public AjaxResult videoExport(AppletsBusiness appletsBusiness)
    {
        if(!SecurityUtils.isAdmin(SecurityUtils.getUserId())){
            appletsBusiness.setDeptId(SecurityUtils.getDeptId());
        }
        List<AppletsBusiness> list = appletsBusinessService.selectAppletsBusinessVideoList(appletsBusiness);
        list.forEach(kv->{
            kv.setDeptName(ywInitData.getDeptMap().get(kv.getDeptId()));
            List<String> videoXx = new ArrayList<>();
            AppletsBusinessVideo appletsBusinessVideo=new AppletsBusinessVideo();
            appletsBusinessVideo.setBusinessid(kv.getId());
            List<AppletsBusinessVideo> appletsBusinessVideoList=appletsBusinessVideoService.selectAppletsBusinessVideoList(appletsBusinessVideo);
            appletsBusinessVideoList.forEach(vv->{
                if (!"".equals(StringUtils.isHcNull(vv.getVideoUrl(),""))){
                    String  xx = vv.getCustomroomid()  +"(" + DateUtils.parseDateToStr(DateUtils.YYYY_MM_DD_HH_MM_SS,vv.getOperatortime())+")";
                    videoXx.add(xx);
                }
            });
            if (videoXx.size()>0){
                kv.setVideoContent(videoXx.stream().map(String::valueOf).collect(Collectors.joining("、"+String.valueOf((char)10))));
            }
        });
        ExcelUtil<AppletsBusiness> util = new ExcelUtil<AppletsBusiness>(AppletsBusiness.class);
        return util.exportExcel(list, "business");
    }
}
